Public Class OtherPrice
    Protected _year As String
    Protected _Organization As New Organization()
    Protected _Outcome As New Outcome()
    Protected _outcome_price As Double
    Protected _Data As ArrayList
    Protected _DataCurrent As Integer

    Public Property year() As String
        Get
            Return _year
        End Get
        Set(ByVal value As String)
            _year = value
        End Set
    End Property

    Public Property Organization() As Organization
        Get
            Return _Organization
        End Get
        Set(ByVal value As Organization)
            _Organization = value
        End Set
    End Property

    Public Property Outcome() As Outcome
        Get
            Return _Outcome
        End Get
        Set(ByVal value As Outcome)
            _Outcome = value
        End Set
    End Property

    Public Property outcome_price() As Double
        Get
            Return _outcome_price
        End Get
        Set(ByVal value As Double)
            _outcome_price = value
        End Set
    End Property

    Public Function getOtherOutcomeYear() As System.Data.DataSet
        Dim decryptText As New DateUtilities.Encrypt_Data()
        Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
            decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
            "PoliceHealthConnectionString").ToString(), True))
        Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
        objCmd.Connection = objConn
        objCmd.CommandType = CommandType.StoredProcedure
        objCmd.CommandText = "proc_SELECT_OtherPriceYear"

        Dim objDa As New MySql.Data.MySqlClient.MySqlDataAdapter(objCmd)
        Dim objDs As New System.Data.DataSet()
        objDa.Fill(objDs, "OtherOutcomeYear")

        Return objDs
    End Function

    Protected Function getsOtherOutcomeYear() As ArrayList
        Dim outResult As New ArrayList()
        Dim decryptText As New DateUtilities.Encrypt_Data()
        Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
            decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
            "PoliceHealthConnectionString").ToString(), True))
        Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
        objCmd.Connection = objConn
        objCmd.CommandType = CommandType.StoredProcedure
        objCmd.CommandText = "proc_SELECT_OtherPriceYear"

        Dim objDa As New MySql.Data.MySqlClient.MySqlDataAdapter(objCmd)
        Dim objDs As New System.Data.DataSet()
        objDa.Fill(objDs, "OtherOutcomeYear")

        For Each objDr As System.Data.DataRow In objDs.Tables("OtherOutcomeYear").Rows
            Dim obj As OtherPrice = New OtherPrice()
            obj.year = objDr.Item("year").ToString()
            outResult.Add(obj)
        Next

        Return outResult
    End Function

    Public Function getOtherPriceByYearAndOrganize() As System.Data.DataSet
        Dim decryptText As New DateUtilities.Encrypt_Data()
        Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
            decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
            "PoliceHealthConnectionString").ToString(), True))
        Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
        objCmd.Connection = objConn
        objCmd.CommandType = CommandType.StoredProcedure
        objCmd.CommandText = "proc_SELECT_OtherPriceByYearAndOrganize"

        Dim objDa As New MySql.Data.MySqlClient.MySqlDataAdapter(objCmd)
        Dim objDs As New System.Data.DataSet()
        objDa.Fill(objDs, "OtherPriceByYearAndOrganize")

        Return objDs
    End Function

    Protected Function getsOtherPriceByYearAndOrganize(ByVal pYear As String, ByVal pOrganizationID As String) As ArrayList
        Dim outResult As New ArrayList()
        Dim decryptText As New DateUtilities.Encrypt_Data()
        Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
            decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
            "PoliceHealthConnectionString").ToString(), True))
        Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
        objCmd.Connection = objConn
        objCmd.CommandType = CommandType.StoredProcedure
        objCmd.CommandText = "proc_SELECT_OtherPriceByYearAndOrganize"

        Dim objParam As New MySql.Data.MySqlClient.MySqlParameter("inYear", pYear)
        objCmd.Parameters.Add(objParam)

        objParam = New MySql.Data.MySqlClient.MySqlParameter("inOrganizationID", pOrganizationID)
        objCmd.Parameters.Add(objParam)

        Dim objDa As New MySql.Data.MySqlClient.MySqlDataAdapter(objCmd)
        Dim objDs As New System.Data.DataSet()
        objDa.Fill(objDs, "OtherPriceByYearAndOrganize")

        For Each objDr As System.Data.DataRow In objDs.Tables("OtherPriceByYearAndOrganize").Rows
            Dim obj As OtherPrice = New OtherPrice()
            obj.year = pYear
            obj.Organization.organization_id = pOrganizationID
            obj.Outcome.outcome_id = objDr.Item("outcome_id").ToString()
            obj.Outcome.outcome_name = objDr.Item("outcome_name").ToString()
            obj.outcome_price = objDr.Item("outcome_price").ToString()
            outResult.Add(obj)
        Next

        Return outResult
    End Function

    Public Function insertOtherPrice() As Boolean
        Try
            Dim decryptText As New DateUtilities.Encrypt_Data()
            Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
                decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
                "PoliceHealthConnectionString").ToString(), True))
            Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
            objCmd.Connection = objConn
            objCmd.CommandType = CommandType.StoredProcedure
            objCmd.CommandText = "proc_INSERT_OtherPrice"

            Dim objParam As New MySql.Data.MySqlClient.MySqlParameter("inYear", year)
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inOrganizationID", Organization.organization_id)
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inOutcomeID", Outcome.outcome_id)
            objCmd.Parameters.Add(objParam)

            objParam = New MySql.Data.MySqlClient.MySqlParameter("inOutcomePrice", outcome_price)
            objCmd.Parameters.Add(objParam)

            objConn.Open()
            objCmd.ExecuteNonQuery()
            objConn.Close()

            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function

    Public Function NextRecord() As Boolean
        If ((Not _Data Is Nothing) AndAlso (((Not _Data Is Nothing) AndAlso _
            (_DataCurrent < _Data.Count And _Data.Count > 0)))) Then
            _year = _Data(_DataCurrent).year
            _Organization.organization_id = _Data(_DataCurrent).Organization.organization_id
            _Outcome.outcome_id = _Data(_DataCurrent).Outcome.outcome_id
            _Outcome.outcome_name = _Data(_DataCurrent).Outcome.outcome_name
            _outcome_price = _Data(_DataCurrent).outcome_price
            _DataCurrent += 1
            Return True
        End If
        Return False
    End Function

    Public Sub loadOtherPriceYear()
        _Data = New ArrayList
        _DataCurrent = 0
        _Data = getsOtherOutcomeYear()
    End Sub

    Public Sub loadOtherPriceByYearAndOrganizationID(ByVal pYear As String, ByVal pOrganizationID As String)
        _Data = New ArrayList
        _DataCurrent = 0
        _Data = getsOtherPriceByYearAndOrganize(pYear, pOrganizationID)
    End Sub

End Class
